package nodes;

import java.util.Queue;
import java.util.ResourceBundle;
import parser.ParserException;
import model.Model;


/**
 * An abstract node that will be used to create the expression tree
 * 
 * @author Andrew Patterson
 */
public abstract class AbstractNode
{
    public static final ResourceBundle syntaxBundle = ResourceBundle.getBundle("resources.syntax_labels");
    public AbstractNode myNext; // Stores function arguments; null by default
    public Model myModel;
    public String myName;   // This node's name


    public AbstractNode (Model model)
    {
        myModel = model;
    }
    
    
    /**
     * Evaluates the current node by either recursing further down the tree,
     * performing some action or returning some value. This method is node
     * specific
     * 
     * @return
     */
    public abstract AbstractNode evaluate ();


    /**
     * Creates this node and builds the tree
     * 
     * @param stack
     * @return an abstract node
     */
    public AbstractNode buildTree (Queue<AbstractNode> stack)
    {
        return this;
    }
    
    /**
     * Returns this node's value.  Error by default
     */
    public int getValue()
    {
        throw ParserException.BAD_TOKEN;
    }

    /**
     * Returns this node's argument(s)
     */
    public AbstractNode getNext ()
    {
        return myNext;
    }
    
    /**
     * Sets this node's argument(s)
     */
    public void setNext (AbstractNode next)
    {
        myNext = next;
    }
    
    @Override
    public String toString ()
    {
        return myName;
    }
}
